// MainActivity.kt
package com.mxun.winefox

import android.app.Application
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.mxun.winefox.ui.theme.WinefoxTheme
import androidx.lifecycle.viewmodel.compose.viewModel


// MainActivity.kt
class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContent {
            WinefoxTheme {
                // 使用 viewModel() 的 Compose 扩展
                val viewModel: MainViewModel = viewModel(
                    factory = MainViewModelFactory(application)
                )
                MainScreen(viewModel = viewModel)
            }
        }
    }
}

// 用于创建ViewModel的Factory
class MainViewModelFactory(private val application: Application) : ViewModelProvider.Factory {
    override fun <T : ViewModel> create(modelClass: Class<T>): T {
        return MainViewModel(application) as T
    }
}